package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.PaymentLimitApply;
import com.ruoyi.web.service.IPaymentLimitApplyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代付限额申请Controller
 * 
 * @author ruoyi
 * @date 2021-04-03
 */
@Controller
@RequestMapping("/pay/apply")
public class PaymentLimitApplyController extends BaseController
{
    private String prefix = "pay/apply";

    @Autowired
    private IPaymentLimitApplyService paymentLimitApplyService;

    @RequiresPermissions("pay:apply:view")
    @GetMapping()
    public String apply()
    {
        return prefix + "/apply";
    }

    /**
     * 查询代付限额申请列表
     */
    @RequiresPermissions("pay:apply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaymentLimitApply paymentLimitApply)
    {
        startPage();
        List<PaymentLimitApply> list = paymentLimitApplyService.selectPaymentLimitApplyList(paymentLimitApply);
        return getDataTable(list);
    }

    /**
     * 导出代付限额申请列表
     */
    @RequiresPermissions("pay:apply:export")
    @Log(title = "代付限额申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaymentLimitApply paymentLimitApply)
    {
        List<PaymentLimitApply> list = paymentLimitApplyService.selectPaymentLimitApplyList(paymentLimitApply);
        ExcelUtil<PaymentLimitApply> util = new ExcelUtil<PaymentLimitApply>(PaymentLimitApply.class);
        return util.exportExcel(list, "apply");
    }

    /**
     * 新增代付限额申请
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代付限额申请
     */
    @RequiresPermissions("pay:apply:add")
    @Log(title = "代付限额申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaymentLimitApply paymentLimitApply) throws Exception
    {
        return toAjax(paymentLimitApplyService.insertPaymentLimitApply(paymentLimitApply));
    }

    /**
     * 修改代付限额申请
     */
    @GetMapping("/edit/{sequenceNo}")
    public String edit(@PathVariable("sequenceNo") String sequenceNo, ModelMap mmap)
    {
        PaymentLimitApply paymentLimitApply = paymentLimitApplyService.selectPaymentLimitApplyById(sequenceNo);
        mmap.put("paymentLimitApply", paymentLimitApply);
        return prefix + "/edit";
    }

    /**
     * 修改保存代付限额申请
     */
    @RequiresPermissions("pay:apply:edit")
    @Log(title = "代付限额申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaymentLimitApply paymentLimitApply)
    {
        return toAjax(paymentLimitApplyService.updatePaymentLimitApply(paymentLimitApply));
    }

    /**
     * 删除代付限额申请
     */
    @RequiresPermissions("pay:apply:remove")
    @Log(title = "代付限额申请", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paymentLimitApplyService.deletePaymentLimitApplyByIds(ids));
    }
}
